﻿namespace ContactSMS.Client.Service
{
    public class AuthService
    {
        private const string AccessTokenKey = "accessToken";
        private const string RefreshTokenKey = "refreshToken";

        // 判断用户是否已登录（检查是否存在 accessToken）
        public static bool IsUserLoggedIn => !string.IsNullOrEmpty(SecureStorage.GetAsync(AccessTokenKey).Result);

        // 存储 accessToken 和 refreshToken
        public static async Task LogInAsync(string accessToken, string refreshToken)
        {
            await SecureStorage.SetAsync(AccessTokenKey, accessToken);
            await SecureStorage.SetAsync(RefreshTokenKey, refreshToken);
        }

        // 获取存储的 accessToken
        public static async Task<string> GetAccessTokenAsync()
        {
            return await SecureStorage.GetAsync(AccessTokenKey);
        }

        // 获取存储的 refreshToken
        public static async Task<string> GetRefreshTokenAsync()
        {
            return await SecureStorage.GetAsync(RefreshTokenKey);
        }

        // 删除存储的 accessToken 和 refreshToken (用户登出)
        public static void LogOut()
        {
            SecureStorage.Remove(AccessTokenKey);
            SecureStorage.Remove(RefreshTokenKey);
        }
    }
}
